# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=todoman
pkgver=4.2.1
pkgrel=2
pkgdesc="A simple, standards-based, cli todo (aka: task) manager"
arch=(any)
url="https://github.com/pimutils/todoman"
license=(ISC)
depends=(
  python
  python-atomicwrites
  python-click
  python-click-log
  python-dateutil
  python-humanize
  python-icalendar
  python-parsedatetime
  python-pyxdg
  python-urwid
)
makedepends=(
  python-build
  python-installer
  python-sphinx-autorun
  python-sphinx-click
  python-sphinx_rtd_theme
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  python-freezegun
  python-hypothesis
  python-pytest
  python-pytest-runner
)
optdepends=(
  'python-click-repl: REPL command'
)
source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz)
sha512sums=('8967e5f6aafd459ebda2b05ec40b249519cd8aa104a0aeb2a19924762f4a482b09c951bd17cfaaf3f973e8f17711f0e8ae1a27f8c041fe775835993f4b4564f5')
b2sums=('d4c53f99a817d60fe5ea9610cdd9e8d1297e6c7e29c0e50b2160f107b2326d4f900db2d8dc9b1ea1c2a7a8ba4efdd6353b7b11335cb30e1b999f7c28acf02a51')

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
  PYTHONPATH="$PYTHONPATH:$PWD" make -C docs man
}

check() {
  cd $pkgname-$pkgver
  export PYTHONPATH="build:$PYTHONPATH"
  # tests require timezone to be set to UTC
  # https://github.com/pimutils/todoman/issues/404
  TZ="UTC" pytest -v -c /dev/null
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  # docs
  install -vDm 644 {AUTHORS,CHANGELOG,CODE_OF_CONDUCT,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
  # manpages
  install -vDm 644 docs/build/man/*.1 -t "$pkgdir/usr/share/man/man1/"
  # license
  # wrong name: https://github.com/pimutils/todoman/issues/319
  install -vDm 644 LICENCE -t "$pkgdir/usr/share/licenses/$pkgname/"
  # sample config
  install -vDm 644 "config.py.sample" -t "$pkgdir/usr/share/doc/$pkgname/examples/"
  # completions
  install -vDm 644 contrib/completion/bash/_todo "$pkgdir/usr/share/bash-completion/completions/todo"
  install -vDm 644 contrib/completion/zsh/_todo -t "$pkgdir/usr/share/zsh/site-functions/"
}
